package com.niuke;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * 37. 连续出牌数量
 */
public class NiukeMoni37buhui {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String[] shuZi = scanner.nextLine().split(" ");
        String[] color = scanner.nextLine().split(" ");

        List<Integer> r = new ArrayList<>();
        List<Integer> y = new ArrayList<>();
        List<Integer> b = new ArrayList<>();
        List<Integer> g = new ArrayList<>();

        Map<Character, List<Integer>> type = new HashMap<>();

        for (int i = 0; i < color.length; i++) {
            if ("r".equals(color[i])) {
                r.add(Integer.parseInt(shuZi[i]));
            }
            if ("y".equals(color[i])) {
                y.add(Integer.parseInt(shuZi[i]));
            }
            if ("b".equals(color[i])) {
                b.add(Integer.parseInt(shuZi[i]));
            }
            if ("g".equals(color[i])) {
                g.add(Integer.parseInt(shuZi[i]));
            }
        }

        if (r.size() > 0) {
            type.put('r', r);
        }
        if (y.size() > 0) {
            type.put('y', y);
        }
        if (b.size() > 0) {
            type.put('b', b);
        }
        if (g.size() > 0) {
            type.put('g', g);
        }

        if (type.size() == 1) {
            Set<Character> keys = type.keySet();
            for (Character k : keys) {
                System.out.println(type.get(k).size());
            }
        } else if (type.size() == 2) {
            Set<Character> keys = type.keySet();
            List<Character> keyList = new ArrayList<>(keys);
            Character key1 = keyList.get(0);
            Character key2 = keyList.get(1);

            List<Integer> jiaoJi = new ArrayList<>();
            List<Integer> first = type.get(key1);
            List<Integer> next = type.get(key2);
            for (int i = 0; i < first.size(); i++) {
                if (next.contains(first.get(i))) {
                    jiaoJi.add(first.get(i));
                }
            }
            System.out.println(jiaoJi.size() > 0 ? first.size() + next.size() :
                    Math.max(first.size(), next.size()));
        }

        List<Integer> jiaoJi1 = new ArrayList<>();
        List<Integer> jiaoJi2 = new ArrayList<>();
        List<Integer> jiaoJi3 = new ArrayList<>();

        List<Integer> jiaoJi4 = new ArrayList<>();
        List<Integer> jiaoJi5 = new ArrayList<>();

        List<Integer> jiaoJi6 = new ArrayList<>();

        int res = 0;
        for (int i = 0; i < r.size(); i++) {
            if (y.contains(r.get(i))) {
                jiaoJi1.add(r.get(i));
                res = Math.max(res, r.size() + y.size());
            }
            if (b.contains(r.get(i))) {
                jiaoJi2.add(r.get(i));
                res = Math.max(res, r.size() + b.size());
            }
            if (g.contains(r.get(i))) {
                jiaoJi3.add(r.get(i));
                res = Math.max(res, r.size() + g.size());
            }
        }

        for (int i = 0; i < y.size(); i++) {
            if (b.contains(y.get(i))) {
                jiaoJi4.add(y.get(i));
                res = Math.max(res, y.size() + b.size());
                if (!jiaoJi1.contains(y.get(i)) || (jiaoJi1.contains(y.get(i)) && jiaoJi1.size() > 1)
                        || !jiaoJi2.contains(y.get(i)) || (jiaoJi2.contains(y.get(i)) && jiaoJi2.size() > 1)) {
                    res = Math.max(res, r.size() + y.size() + b.size());
                }
            }
            if (g.contains(y.get(i))) {
                jiaoJi5.add(y.get(i));
                res = Math.max(res, y.size() + g.size());
                if (!jiaoJi1.contains(y.get(i)) || (jiaoJi1.contains(y.get(i)) && jiaoJi1.size() > 1)
                        || !jiaoJi3.contains(y.get(i)) || (jiaoJi3.contains(y.get(i)) && jiaoJi3.size() > 1)) {
                    res = Math.max(res, r.size() + y.size() + g.size());
                }
            }
        }

        for (int i = 0; i < b.size(); i++) {
            if (g.contains(b.get(i))) {
                jiaoJi6.add(b.get(i));
                res = Math.max(res, b.size() + g.size());
                if (!jiaoJi2.contains(b.get(i)) || (jiaoJi2.contains(b.get(i)) && jiaoJi2.size() > 1)
                        || !jiaoJi3.contains(b.get(i)) || (jiaoJi3.contains(b.get(i)) && jiaoJi3.size() > 1)) {
                    res = Math.max(res, r.size() + b.size() + g.size());
                }


                if (!jiaoJi4.contains(b.get(i)) || (jiaoJi4.contains(b.get(i)) && jiaoJi4.size() > 1)
                        || !jiaoJi5.contains(b.get(i)) || (jiaoJi5.contains(b.get(i)) && jiaoJi5.size() > 1)) {
                    res = Math.max(res, y.size() + b.size() + g.size());
                }
            }
        }

        if (jiaoJi1.size() == 0 && jiaoJi2.size() == 0 && jiaoJi3.size() == 0
                && jiaoJi4.size() == 0 && jiaoJi5.size() == 0 && jiaoJi6.size() == 0) {
            res = Math.max(r.size(), y.size());
            res = Math.max(res, b.size());
            res = Math.max(res, g.size());
        }

        System.out.println(res);

    }

}
